//
//  cellSettingViewController.m
//  FCTools
//
//  Created by WJC on 2018/10/25.
//  Copyright © 2018 wjc. All rights reserved.
//

#import "cellSettingViewController.h"

#import "WJCDefine.h"
#import "UIResponder+FCFirstResponder.h"
#import "UIView+viewExtension.h"
#import "NSMutableAttributedString+FCReplaceString.h"

@interface cellSettingViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,assign) bool keyboardShow;
@end

@implementation cellSettingViewController
-(void)setContentWithArr:(NSArray*)titlearr{
    self.contentArr = [NSMutableArray new];
    for (int i=0; i<titlearr.count; i++) {
        NSMutableArray *objArr = [NSMutableArray new];
        for (int j = 0; j < ((NSArray*)titlearr[i]).count; j++) {
            tableObj *obj = [tableObj new];
            [obj setValuesForKeysWithDictionary:titlearr[i][j] ];
            [objArr addObject:obj];
        }
        [self.contentArr addObject:objArr];
    }
    [self setTableContent];
}
-(NSMutableArray*)setCellContentWithArr:(NSArray*)arr{
    NSMutableArray *addArr=[NSMutableArray new];
    for (NSDictionary *dic in arr) {
        tableObj *Obj=[tableObj new];
        [Obj setValuesForKeysWithDictionary:dic];
        [addArr addObject:Obj];
    }
    return addArr;
}
-(tableObj *)setCellWithDic:(NSDictionary *)dic{
    tableObj *Obj=[tableObj new];
    [Obj setValuesForKeysWithDictionary:dic];
    return Obj;
}
-(id)getReturnCellOtherWithCellName:(NSString *)cellName{
    id other=nil;
    for (NSMutableArray *arr in self.contentArr) {
        for (tableObj *obj in arr) {
            if ([obj.name isEqual:cellName]) {
                other= obj.other;
            }
            
        }
    }
    return other;
}
-(NSIndexPath *)getReturnCellIndexWithCellName:(NSString *)cellName{
    NSIndexPath *other=nil;
    for (int i =0 ; i < self.contentArr.count; i++) {
        for (int j = 0 ; j<self.contentArr[i].count; j++) {
            if ([self.contentArr[i][j].name isEqual:cellName]) {
                other=[NSIndexPath indexPathForRow:j inSection:i];
            }
        }
    }
    return other;
}
-(NSIndexPath *)getReturnCellIndexWithItemType:(itemType)ItemType{
    NSIndexPath *other=nil;
    for (int i =0 ; i < self.contentArr.count; i++) {
        for (int j = 0 ; j<self.contentArr[i].count; j++) {
            if (self.contentArr[i][j].itemType ==ItemType) {
                other=[NSIndexPath indexPathForRow:j inSection:i];
            }
        }
    }
    return other;
}
-(tableObj *)getReturnCellWithCellName:(NSString *)cellName{
    tableObj *other=nil;
    for (NSMutableArray *arr in self.contentArr) {
        for (tableObj *obj in arr) {
            if ([obj.name isEqual:cellName]) {
                other= obj;
            }
            
        }
    }
    return other;
}

-(tableObj *)getCellWithCellItemType:(itemType)ItemType{
    tableObj *other=nil;
    for (NSMutableArray *arr in self.contentArr) {
        for (tableObj *obj in arr) {
            if (obj.itemType == ItemType) {
                other= obj;
            }
        }
    }
    return other;
}
-(NSString *)getReturnCellDetailTxtWithCellName:(NSString *)cellName{
    NSString *ValueCell=@"";
    for (NSMutableArray *arr in self.contentArr) {
        for (tableObj *obj in arr) {
            if ([obj.name isEqual:cellName]) {
                ValueCell= obj.value;
            }
            
        }
    }
    return ValueCell;
}
- (void)removeCellWithCellName:(NSString *)cellName{
    for (int i = 0; i<self.contentArr.count; i++) {
        for (int j = 0; j<self.contentArr[i].count; j++) {
            if ([self.contentArr[i][j].name isEqual:cellName]) {
                [self.contentArr[i] removeObjectAtIndex:j];
                if(self.contentArr[i].count<1){
                    [self.contentArr removeObjectAtIndex:i];
                }
                return;
                
                
            }
        }
    }
}
- (void)removeCellWithCellItemType:(itemType)ItemType{
    for (int i = 0; i<self.contentArr.count; i++) {
        for (int j = 0; j<self.contentArr[i].count; j++) {
            if (self.contentArr[i][j].itemType == ItemType) {
                [self.contentArr[i] removeObjectAtIndex:j];
                if(self.contentArr[i].count<1){
                    [self.contentArr removeObjectAtIndex:i];
                }
                return;
                
                
            }
        }
    }
}
-(void)setLineColor:(UIColor *)lineColor{
    _lineColor=lineColor;
     self.tableView.separatorColor =lineColor;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.edgesForExtendedLayout =UIRectEdgeNone;
    self.automaticallyAdjustsScrollViewInsets =NO;
    self.view.backgroundColor=[UIColor whiteColor];
    _tableView=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, WJCScreenW, self.view.frame.size.height) style:UITableViewStylePlain];//[WJCCreateUI createTableViewWithFrame:CGRectMake(0, 40, WJCScreenW, WJCScreenH-40-64) style:UITableViewStylePlain andBackColor:nil];
    _tableView.backgroundColor= HEXC(0xF5F5F5);
    self.tableView.separatorColor =HEXC(0xD8D8D8);
    self.tableView.tableFooterView=[UIView new];
    [self.view addSubview:_tableView];
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.and.bottom.and.top.mas_equalTo(0);
    }];
    
//    [self setTableContent];
    _tableView.dataSource=self;
    _tableView.delegate=self;
    if (@available(iOS 15.0, *)) {
           _tableView.sectionHeaderTopPadding = 0;
       }
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(openKeyBoard:) name:UIKeyboardWillShowNotification object:nil];
    //键盘将要 回去 的通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(closeKeyBoard:) name:UIKeyboardWillHideNotification object:nil];
}
-(void)viewWillDisappear:(BOOL)animated{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
-(void)viewWillAppear:(BOOL)animated{
    _keyboardShow=NO;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(openKeyBoard:) name:UIKeyboardWillShowNotification object:nil];
    //键盘将要 回去 的通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(closeKeyBoard:) name:UIKeyboardWillHideNotification object:nil];
}
-(void)setTableContent{
    if (!self.contentArr) {
        NSMutableArray *arr1=[NSMutableArray new];
        
        NSArray *obj=@[@{@"name":@"供货类型",@"placeHolder": @"请选择供货类型",@"height":@44},];
        for (NSDictionary *dic in obj) {
            tableObj *obj=[tableObj new];
            [obj setValuesForKeysWithDictionary:dic];
            [arr1 addObject:obj];
        }
        NSArray *obj2=@[@{@"placeHolder": @"接单回复：如产品的介绍、生产的优势等…",@"type":@2,@"height":@120}];
        NSMutableArray *arr2=[NSMutableArray new];
        for (NSDictionary *dic in obj2) {
            tableObj *obj=[tableObj new];
            [obj setValuesForKeysWithDictionary:dic];
            [arr2 addObject:obj];
        }
        NSArray *obj3=@[ @{@"name":@"产品单价",@"placeHolder":@"请填写产品单价,0为面议",@"type":@1,@"height":@44}
                         ];
        NSMutableArray *arr3=[NSMutableArray new];
        for (NSDictionary *dic in obj3) {
            tableObj *obj=[tableObj new];
            [obj setValuesForKeysWithDictionary:dic];
            [arr3 addObject:obj];
        }
        _contentArr=[NSMutableArray new];
        [_contentArr addObject:arr1];
        [_contentArr addObject:arr2];
        [_contentArr addObject:arr3];
    }
    
    [self.tableView reloadData];
    
}

-(void)setupTableObj:(NSArray*)dataAry{
    NSMutableArray *ary = [NSMutableArray new];
    for (NSDictionary *dic in dataAry) {
        tableObj *obj=[tableObj new];
        [obj setValuesForKeysWithDictionary:dic];
        [ary addObject: obj];
    }
    [self.contentArr addObject:ary];
}

-(void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

-(void)openKeyBoard:(NSNotification*)notification {
    WJCWeakSelf
    
    if (_keyboardShow==NO) {
        self.codeDrag=YES;
    
    _keyboardShow=YES;
    CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    id txt=[UIResponder currentFirstResponder];
    if ([txt isKindOfClass:[UITextView class]]) {
        UITextView *text=txt;
        CGRect frame = [text.superview convertRect:text.frame toView:self.view];
        if (frame.origin.y+frame.size.height+44+self.keyBoardotherHeight>keyboardFrame.origin.y) {
            
            if (IPhoneX) {
                [_tableView setContentOffset:CGPointMake(0, _tableView.contentOffset.y+frame.origin.y+frame.size.height-keyboardFrame.origin.y+self.view.frame.origin.y+20+self.keyBoardotherHeight) animated:YES];
            }else{
                [_tableView setContentOffset:CGPointMake(0, _tableView.contentOffset.y+frame.origin.y+frame.size.height-keyboardFrame.origin.y+self.view.frame.origin.y+self.keyBoardotherHeight) animated:YES];
            }
        }
        if ([self.settingDelegate respondsToSelector:@selector(keyboardWillShowWithNotification: cellForRowAtIndexPath:)]) {
            CGPoint point = [text.superview convertPoint:text.frame.origin toView:self.tableView];
            NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:point];
            [self.settingDelegate keyboardWillShowWithNotification:notification cellForRowAtIndexPath:indexPath];
        }
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            self.codeDrag=NO;
        });
    }
    else if ([txt isKindOfClass:[UITextField class]]) {
        UITextField *text=txt;
        CGRect frame = [text.superview convertRect:text.frame toView:self.view];
        if (frame.origin.y+frame.size.height+44+self.keyBoardotherHeight>keyboardFrame.origin.y) {
            
            if (IPhoneX) {
                [_tableView setContentOffset:CGPointMake(0, _tableView.contentOffset.y+frame.origin.y+frame.size.height-keyboardFrame.origin.y+self.view.frame.origin.y+20+44+self.keyBoardotherHeight) animated:YES];
            }else{
                [_tableView setContentOffset:CGPointMake(0, _tableView.contentOffset.y+frame.origin.y+frame.size.height-keyboardFrame.origin.y+self.view.frame.origin.y+44+self.keyBoardotherHeight) animated:YES];
            }
        }
        if ([self.settingDelegate respondsToSelector:@selector(keyboardWillShowWithNotification: cellForRowAtIndexPath:)]) {
            CGPoint point = [text.superview convertPoint:text.frame.origin toView:self.tableView];
            NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:point];
            [self.settingDelegate keyboardWillShowWithNotification:notification cellForRowAtIndexPath:indexPath];
        }
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            weakSelf.codeDrag=NO;
        });
    }
    }
}

-(void)closeKeyBoard:(NSNotification*)notification {
    if (_keyboardShow==YES) {
        _keyboardShow=NO;
    
    WJCWeakSelf
    id txt=[UIResponder currentFirstResponder];
    if ([txt isKindOfClass:[UITextView class]]) {
        UITextView *text=txt;
        if ([self.settingDelegate respondsToSelector:@selector(keyboardWillHideWithNotification: cellForRowAtIndexPath: andkeyBorardTool:)]) {
            CGPoint point = [text.superview convertPoint:text.frame.origin toView:self.tableView];
            NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:point];
            [self.settingDelegate keyboardWillHideWithNotification:notification cellForRowAtIndexPath:indexPath andkeyBorardTool:txt];
        }
    }
    else if ([txt isKindOfClass:[UITextField class]]) {
        UITextField *text=txt;
        if ([self.settingDelegate respondsToSelector:@selector(keyboardWillHideWithNotification: cellForRowAtIndexPath: andkeyBorardTool:)]) {
            CGPoint point = [text.superview convertPoint:text.frame.origin toView:self.tableView];
            NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:point];
            [self.settingDelegate keyboardWillHideWithNotification:notification cellForRowAtIndexPath:indexPath andkeyBorardTool:txt];
        }
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            weakSelf.codeDrag=NO;
        });
    }
    [_tableView reloadData];
    _codeDrag=NO;
    }
}
#pragma mark--tableviewdelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.contentArr.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _contentArr[section].count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (_contentArr[indexPath.section][indexPath.row].automaticHeight) {
        return UITableViewAutomaticDimension;
    }
    
     if( _contentArr[indexPath.section][indexPath.row].type==1||_contentArr[indexPath.section][indexPath.row].type==5){
         return FCScaleHeight(44);
//         if(IphonePlus && _contentArr[indexPath.section][indexPath.row].height<55) return 54;
//         if(_contentArr[indexPath.section][indexPath.row].height<45) return 48;
     }
    if( _contentArr[indexPath.section][indexPath.row].type==7){
        UILabel *titleLabel=[UILabel new];
        titleLabel.font=font15;
        titleLabel.text=_contentArr[indexPath.section][indexPath.row].name;
        if(_contentArr[indexPath.section][indexPath.row].choice){
            NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@  ＊",_contentArr[indexPath.section][indexPath.row].name]];
            [string replaceColorWithStr:@"＊" andColor:[UIColor redColor]];
            titleLabel.attributedText=string;
        }
        [titleLabel sizeToFit];
        UILabel *detailLabel=[UILabel new];
        detailLabel.font=font15;
         detailLabel.frame=CGRectMake(titleLabel.frame.origin.x+titleLabel.frame.size.width+32, 12, WJCScreenW-(128+48), 999);
        detailLabel.numberOfLines=0;
        detailLabel.text=_contentArr[indexPath.section][indexPath.row].value;
        [detailLabel sizeToFit];
        if (detailLabel.frame.size.height>28) {
            return detailLabel.frame.size.height+FCScaleHeight(16);
        }else{
             FCScaleHeight(44);
        }
    }
    if( _contentArr[indexPath.section][indexPath.row].type==4){
        UILabel *titleLabel=[UILabel new];
        titleLabel.font=font15;
        titleLabel.numberOfLines=0;
        titleLabel.frame=CGRectMake(16, 12, 80, 20);
        titleLabel.text=_contentArr[indexPath.section][indexPath.row].name;
        if(_contentArr[indexPath.section][indexPath.row].choice){
            NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@  ＊",_contentArr[indexPath.section][indexPath.row].name]];
            [string replaceColorWithStr:@"＊" andColor:[UIColor redColor]];
            titleLabel.attributedText=string;
        }
        UILabel *detailLabel=[UILabel new];
        detailLabel.font=font15;
        detailLabel.numberOfLines=0;
        detailLabel.text=_contentArr[indexPath.section][indexPath.row].value;
        detailLabel.frame=CGRectMake(titleLabel.frame.origin.x+titleLabel.frame.size.width+32, 12, WJCScreenW-(128+48), 80);
        [detailLabel sizeToFit];
        [titleLabel sizeToFit];
        if (detailLabel.frame.size.height>28) {
            return detailLabel.frame.size.height+16;
        }else if (titleLabel.frame.size.height>28) {
            return titleLabel.frame.size.height+16;
        }
        else{
            FCScaleHeight(44);
        }
    }
    if( _contentArr[indexPath.section][indexPath.row].height<44) return FCScaleHeight(44);;
    return _contentArr[indexPath.section][indexPath.row].height;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
   return 8.0f;;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view=[UIView new];

    view.backgroundColor= HEXC(0xF5F5F5);
    return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.01f;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view=[UIView new];
    view.backgroundColor= HEXC(0xF5F5F5);
    return view;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    tableObj *obj=_contentArr[indexPath.section][indexPath.row];
    switch (obj.type) {
        case 0:
            case 4:
        case 7:
        {
        TableTxtChoiceViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"choiceCell"];
        if(!cell){
            cell=[[TableTxtChoiceViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"choiceCell"];
            
        }
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        if (self.isCloseEdit||obj.hiddenAccessory) {
             cell.accessoryType=UITableViewCellAccessoryNone;
        }
        cell.titleLabel.text=obj.name;
        if(obj.choice){
            NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@  ＊",obj.name]];
            [string replaceColorWithStr:@"＊" andColor:[UIColor redColor]];
            cell.titleLabel.attributedText=string;
        }
            cell.detailLabel.textColor = HEXC(0xCCCCCC);
        cell.detailTextLabel.textAlignment=NSTextAlignmentLeft;
        if (obj.value&&obj.value.length>0) {
            cell.detailLabel.text=obj.value;
            [cell.titleLabel sizeToFit];
            cell.detailLabel.textColor = HEXC(0x646262);
        }
        else cell.detailLabel.text=obj.placeHolder;
        
        if(obj.type==7){
            cell.detailLabel.numberOfLines=0;
            cell.detailLabel.height=999;
            cell.detailLabel.text=obj.value;
             [cell.detailLabel sizeToFit];
            [cell setfit];
        }
        if(obj.type==4){
            cell.detailLabel.textAlignment=NSTextAlignmentLeft;
            cell.titleLabel.numberOfLines=0;
            cell.titleLabel.frame=CGRectMake(16, 12, 80, 80);
            [cell.titleLabel sizeToFit];
            cell.detailLabel.frame=CGRectMake(96+32, 12, WJCScreenW-(128+(cell.accessoryType==UITableViewCellAccessoryDisclosureIndicator?32:10)), 80);
            cell.detailLabel.numberOfLines=0;
            [cell.detailLabel sizeToFit];
            if(cell.detailLabel.height>28){
                cell.detailLabel.y=8;
                
            }
            if(cell.titleLabel.height>28){
                cell.titleLabel.y=8;
                if(cell.detailLabel.height<cell.titleLabel.height){
                    cell.detailLabel.y=(cell.titleLabel.y+cell.titleLabel.height)*0.5-4;
                    
                }
            }
            [cell setfit];
        }else{
             [cell setfit];
        }
       
        if ([self.settingDelegate respondsToSelector:@selector(getComontableView:andTableViewCell:cellForRowAtIndexPath:)]) {
            [self.settingDelegate getComontableView:tableView andTableViewCell:cell cellForRowAtIndexPath:indexPath];
        }

//             cell.separatorInset = UIEdgeInsetsMake(0, cell.contentView.bounds.size.width, 0, 0);
//             }else{
//              cell.separatorInset = UIEdgeInsetsMake(0, cell.contentView.bounds.size.height-1, 0, 10+FTDefaultMenuTextMargin);
//                 }
        return cell;
        }
            
            break;
        case 1:
             case 5:
        {
        TableTextFieldViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"textFieldCell"];
        
        if(!cell){
            cell=[[TableTextFieldViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"textFieldCell"];
            cell.accessoryType=UITableViewCellAccessoryNone;
        }
            cell.txtBlock = ^(UILabel *titleLabel, UITextField *txtField) {
                obj.value=txtField.text;
            };
        
            //[FCRightTextTableViewCell cellForTableView:tableView andunstyle:UITableViewCellAccessoryNone andIndexPath:indexPath];
        cell.textField.textColor=WJCColor(35, 35, 35);
        cell.textField.keyboardType=obj.keyboardType;
        [cell.textField addTarget:self action:@selector(textDidEnd) forControlEvents:UIControlEventEditingDidEndOnExit];
        cell.titleLabel.text=obj.name;
        if(obj.choice){
            NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@  ＊",obj.name]];
            [string replaceColorWithStr:@"＊" andColor:[UIColor redColor]];
            cell.titleLabel.attributedText=string;
        }
        if (self.isCloseEdit||obj.hiddenAccessory) {
            cell.textField.enabled=NO;
        }
        if (obj.value) {
            cell.textField.text=obj.value;
        }else{
            cell.textField.text=@"";
        }
        if (obj.placeHolder) {
            
            cell.textField.placeholder=obj.placeHolder;
            NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:obj.placeHolder attributes:
                                              @{NSForegroundColorAttributeName:HEXC(0xCCCCCC),
                                                NSFontAttributeName:cell.textField.font
                                                }];
            cell.textField.attributedPlaceholder = attrString;
        }
        cell.maxCount=obj.maxCount;
            if(obj.maxCount>5){
                cell.countLabel.hidden = NO;
            }
         [cell setfit];
            
        if(obj.type==5)cell.textField.textAlignment=NSTextAlignmentLeft;
       
        WJCWeakSelf
        cell.txtEndBlock = ^(UILabel *titleLabel, UITextField *txtField) {
            if ([weakSelf.settingDelegate respondsToSelector:@selector(keyboardWillHideWithNotification: cellForRowAtIndexPath: andkeyBorardTool:)]) {
                [weakSelf.settingDelegate keyboardWillHideWithNotification:nil cellForRowAtIndexPath:indexPath andkeyBorardTool:txtField];
            }
        };
        if ([weakSelf.settingDelegate respondsToSelector:@selector(getComontableView:andTableViewCell:cellForRowAtIndexPath:)]) {
            [weakSelf.settingDelegate getComontableView:tableView andTableViewCell:cell cellForRowAtIndexPath:indexPath];
        }
        return cell;
        }
            
            break;
        case 2:
        case 6:
        {
        TableTextViewViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"textviewCell"];
        if(!cell){
            cell=[[TableTextViewViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"textviewCell"];
            cell.accessoryType=UITableViewCellAccessoryNone;
        }
        
        cell.noteTxtplaceHolder.text=obj.placeHolder;
        cell.placeHolder=obj.placeHolder;
            cell.maxCount=obj.maxCount;
        if (self.isCloseEdit||obj.hiddenAccessory) {
            cell.noteTxtView.editable=NO;
            cell.noteTxtplaceHolder.hidden=YES;
            cell.noteLabel.hidden=YES;
        }
        if (obj.value.length>0) {
            cell.noteTxtView.text=obj.value;
            cell.noteTxtplaceHolder.text=@"";
        }
        if (obj.type==6) {
            cell.noteLabel.hidden=NO;
            cell.noteLabel.text=obj.name;
        }
        [cell setfit];
        cell.returnBlock = ^(UITextView *view) {
            obj.value=view.text;
            
        };
        if ([self.settingDelegate respondsToSelector:@selector(getComontableView:andTableViewCell:cellForRowAtIndexPath:)]) {
            [self.settingDelegate getComontableView:tableView andTableViewCell:cell cellForRowAtIndexPath:indexPath];
        }
        return cell;
        }
            break;
        case 3:
        {
        switchCellTableViewCell *cell=[switchCellTableViewCell cellWithNoneImageForTableView:tableView andunstyle:UITableViewCellAccessoryNone];
//        if(obj.choice){
//            NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@  ＊",obj.name]];
//            [string replaceColorWithStr:@"＊" andColor:[UIColor redColor]];
//            cell.titleLabel.attributedText=string;
//        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.titleLabel.text=obj.name;
            [cell.titleLabel sizeToFit];
        cell.switchChoice.on=obj.choice;
        cell.switchBlock = ^(UISwitch *choice) {
            obj.choice=choice.on;
        };
        if ([self.settingDelegate respondsToSelector:@selector(getComontableView:andTableViewCell:cellForRowAtIndexPath:)]) {
            [self.settingDelegate getComontableView:tableView andTableViewCell:cell cellForRowAtIndexPath:indexPath];
        }
        return cell;
        }
            
            break;
//        case 8:{
//            FCTIBLTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TIBLTableViewCell"];
//            if (!cell) {
//                cell = [[FCTIBLTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TIBLTableViewCell" andCellHeight:self.contentArr[indexPath.section][indexPath.row].height];
//                
//            }
//            cell.contentBtn = self.contentArr[indexPath.section][indexPath.row].other;
//            cell.ruleView.delegate = self;
//            return cell;
//        }
//            break;
        case 9:{
            FCImgChoicedTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FCImgChoicedTableViewCell"];
            if (!cell) {
                cell = [[FCImgChoicedTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"FCImgChoicedTableViewCell"];
                
            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            cell.obj = obj;
            cell.parentTableView = tableView;
            cell.index = indexPath;
            return cell;
        }
            break;
        case 10:
        {
        FCChoiceRadiusTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"btnCell"];
        if(!cell){
            cell=[[FCChoiceRadiusTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"btnCell"];
            
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
             cell.accessoryType=UITableViewCellAccessoryNone;
        cell.unionChoiced = YES;
        cell.titleLabel.text=obj.name;
        if(obj.choice){
            NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@  ＊",obj.name]];
            [string replaceColorWithStr:@"＊" andColor:[UIColor redColor]];
            cell.titleLabel.attributedText=string;
        }
            cell.rightBtns = obj.other;
        [cell setfit];
       
        cell.idBlock = ^(UIButton *object) {
            obj.choicedCount = object.tag;
        };
       
        if ([self.settingDelegate respondsToSelector:@selector(getComontableView:andTableViewCell:cellForRowAtIndexPath:)]) {
            [self.settingDelegate getComontableView:tableView andTableViewCell:cell cellForRowAtIndexPath:indexPath];
        }

//             cell.separatorInset = UIEdgeInsetsMake(0, cell.contentView.bounds.size.width, 0, 0);
//             }else{
//              cell.separatorInset = UIEdgeInsetsMake(0, cell.contentView.bounds.size.height-1, 0, 10+FTDefaultMenuTextMargin);
//                 }
        return cell;
        }
            
            break;
        case 11:
        {
        TableTxtChoiceViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"choiceImgCell"];
        if(!cell){
            cell=[[TableTxtChoiceViewCell alloc] initGetImageWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"choiceImgCell"];
            
        }
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        if (self.isCloseEdit||obj.hiddenAccessory) {
             cell.accessoryType=UITableViewCellAccessoryNone;
        }
            if ([obj.other isKindOfClass:[UIImage class]]) {
                cell.leftImage.image = obj.other;
            }else{
                if ([obj.other isKindOfClass:[NSString class]]) {
                    NSString *s = obj.other;
                    if ([s isUrl]) {
                        [cell.leftImage fc_setImageWithURL:s placeholder:[WJCDeployModel getDeployWithDeployKey:WJCDeployHeadImage] completed:nil];
                    }else{
                        cell.leftImage.image = [UIImage imageNamed:s];
                    }
                }
            }
        cell.titleLabel.text=obj.name;
        if(obj.choice){
            NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@  ＊",obj.name]];
            [string replaceColorWithStr:@"＊" andColor:[UIColor redColor]];
            cell.titleLabel.attributedText=string;
        }
        cell.detailTextLabel.textAlignment=NSTextAlignmentLeft;
        if (obj.value&&obj.value.length>0) {
            cell.detailLabel.text=obj.value;
            [cell.titleLabel sizeToFit];
            
        }
        else cell.detailLabel.text=obj.placeHolder;
        
             [cell setfit];
        if ([self.settingDelegate respondsToSelector:@selector(getComontableView:andTableViewCell:cellForRowAtIndexPath:)]) {
            [self.settingDelegate getComontableView:tableView andTableViewCell:cell cellForRowAtIndexPath:indexPath];
        }

        return cell;
        }
        case 12:
        {
        TableTxtChoiceViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"choiceRightImgCell"];
        if(!cell){
            cell=[[TableTxtChoiceViewCell alloc] initGetRightImageWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"choiceRightImgCell"];
            
        }
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        if (self.isCloseEdit||obj.hiddenAccessory) {
             cell.accessoryType=UITableViewCellAccessoryNone;
        }
            if ([obj.other isKindOfClass:[UIImage class]]) {
                cell.leftImage.image = obj.other;
            }else{
                if ([obj.other isKindOfClass:[NSString class]]) {
                    NSString *s = obj.other;
                    if ([s isUrl]) {
                        [cell.leftImage fc_setImageWithURL:s placeholder:[WJCDeployModel getDeployWithDeployKey:WJCDeployHeadImage] completed:nil];
                    }else{
                        cell.leftImage.image = [UIImage imageNamed:s];
                    }
                }
            }
        cell.titleLabel.text=obj.name;
        if(obj.choice){
            NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@  ＊",obj.name]];
            [string replaceColorWithStr:@"＊" andColor:[UIColor redColor]];
            cell.titleLabel.attributedText=string;
        }
        cell.detailTextLabel.textAlignment=NSTextAlignmentLeft;
        if (obj.value&&obj.value.length>0) {
            cell.detailLabel.text=obj.value;
            [cell.titleLabel sizeToFit];
            
        }
        else cell.detailLabel.text=obj.placeHolder;
        if ([self.settingDelegate respondsToSelector:@selector(getComontableView:andTableViewCell:cellForRowAtIndexPath:)]) {
            [self.settingDelegate getComontableView:tableView andTableViewCell:cell cellForRowAtIndexPath:indexPath];
        }
        return cell;
        }
        default:{
            if(obj.type==99){
                if ([self.settingDelegate respondsToSelector:@selector(getOthertableView:cellForRowAtIndexPath:)]) {
                    return [self.settingDelegate getOthertableView:tableView cellForRowAtIndexPath:indexPath];
                }
            }
            return [[UITableViewCell alloc]init];
        }
            break;
    }
}
//- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    [cell setLayoutMargins:UIEdgeInsetsMake(0, 10, 0, 10)];
//    [cell setSeparatorInset:UIEdgeInsetsMake(0,10, 0, 10)];
//}
-(void)textDidEnd{
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (self.contentArr[indexPath.section][indexPath.row].pushController) {
        [self pushAppControllerWithControllerName:self.contentArr[indexPath.section][indexPath.row].pushController andObjectData:self.contentArr[indexPath.section][indexPath.row].pushControllerMode andTitle:self.contentArr[indexPath.section][indexPath.row].name];
    }
}
    //去掉UItableview headerview黏性(sticky)
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    if ([UIResponder currentFirstResponder]&&!_codeDrag) {
        [[UIResponder currentFirstResponder] resignFirstResponder];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.topAndBottomRadiu>0) {
    if (self.contentArr[indexPath.section].count>0&&self.contentArr[indexPath.section].count==1) {
        CGPathRef path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, tableView.width,cell.height)
                                               byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(self.topAndBottomRadiu, self.topAndBottomRadiu)].CGPath;
        CAShapeLayer *lay = [CAShapeLayer layer];
        lay.path = path;
        [lay masksToBounds];
        cell.layer.mask =lay;;
    }

       else if (self.contentArr[indexPath.section].count>0&&indexPath.row==0) {
            CGPathRef path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, tableView.width,cell.height)
                                                   byRoundingCorners:UIRectCornerTopRight|UIRectCornerTopLeft cornerRadii:CGSizeMake(self.topAndBottomRadiu, self.topAndBottomRadiu)].CGPath;
            CAShapeLayer *lay = [CAShapeLayer layer];
            lay.path = path;
            [lay masksToBounds];
            cell.layer.mask =lay;;
        }else if (self.contentArr[indexPath.section].count>0&&indexPath.row==self.contentArr[indexPath.section].count-1){
            CGPathRef path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, tableView.width, cell.height)
                                                   byRoundingCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight cornerRadii:CGSizeMake(self.topAndBottomRadiu, self.topAndBottomRadiu)].CGPath;
            CAShapeLayer *lay = [CAShapeLayer layer];
            lay.path = path;
            [lay masksToBounds];
            cell.layer.mask =lay;
        }else{
            cell.layer.mask =nil;
        }
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
